//
//  ViewController.m
//  SetupViewController
//
//  Created by Gamefire on 16/4/19.
//  Copyright © 2016年 Gamefire. All rights reserved.
//

#import "SetupViewController.h"
#import "SDImageCache.h"
#import "Header.h"


#import "AboutUSViewController.h"

@interface SetupViewController ()

@end

@implementation SetupViewController
- (void)loadView{
    [super loadView];
    self.navigationController.navigationBarHidden = YES;
    
    [self.view setBackgroundColor:[UIColor colorWithRed:236.0/255.0 green:236.0/255.0 blue:236.0/255.0 alpha:1]];
    
    UIView *navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
    [navigationView setBackgroundColor:[UIColor colorWithRed:242.0 /255.0 green:202.0 /255.0 blue:48.0/255.0 alpha:1]];
    [self.view addSubview:navigationView];
    
    UIImageView *leftimageView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 29, 10, 20)];
//    [leftimageView setBackgroundColor:[UIColor redColor]];
    [leftimageView setImage:[UIImage imageNamed:@"Detalback"]];
    [navigationView addSubview:leftimageView];
    
    UILabel *namelabel = [[UILabel alloc] initWithFrame:CGRectMake(navigationView.bounds.size.width / 2.0 - 20, 29, 40, 20)];
    [namelabel setText:@"设置"];
    [namelabel setFont:[UIFont systemFontOfSize:16.0]];
    [navigationView addSubview:namelabel];
    
    UILabel *setUpLabel = [[UILabel alloc] initWithFrame:CGRectMake(23, 27, 33, 24)];
    [setUpLabel setText:@"返回"];
    [setUpLabel setTextAlignment:NSTextAlignmentCenter];
    [setUpLabel setFont:[UIFont systemFontOfSize:15.0]];
    [setUpLabel setTextColor:[UIColor blackColor]];
    [self.view addSubview:setUpLabel];
    
    UIButton *leftbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 25, 60, 60)];
    [leftbtn addTarget:self action:@selector(leftEvent:) forControlEvents:UIControlEventTouchUpInside];
//    [leftbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [leftbtn.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [navigationView addSubview:leftbtn];
    
    UIButton *cachebtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(navigationView.frame) + 10.0, [UIScreen mainScreen].bounds.size.width, 49)];
    [cachebtn setBackgroundColor:[UIColor whiteColor]];
    [cachebtn addTarget:self action:@selector(cacheEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cachebtn];
    
    UIButton *opinionbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(cachebtn.frame) + 10.0, [UIScreen mainScreen].bounds.size.width, 49)];
    [opinionbtn setBackgroundColor:[UIColor whiteColor]];
    [opinionbtn addTarget:self action:@selector(opinionEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:opinionbtn];
    
    UIButton *aboutbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(opinionbtn.frame) + 10.0, [UIScreen mainScreen].bounds.size.width, 49)];
    [aboutbtn setBackgroundColor:[UIColor whiteColor]];
    [aboutbtn addTarget:self action:@selector(aboutEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:aboutbtn];

    UIButton *exitbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(aboutbtn.frame) + 10.0, [UIScreen mainScreen].bounds.size.width, 49)];
    [exitbtn setBackgroundColor:[UIColor whiteColor]];
    [exitbtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [exitbtn addTarget:self action:@selector(exitEvent:) forControlEvents:UIControlEventTouchUpInside];
    [exitbtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:exitbtn];
    
    UILabel *cachelabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 60, 15)];
    [cachelabel setBackgroundColor:[UIColor whiteColor]];
    [cachelabel setText:@"清除缓存"];
    [cachelabel setFont:[UIFont systemFontOfSize:15.0]];
    [cachebtn addSubview:cachelabel];
    
    UILabel *opinionlabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 60, 15)];
    [opinionlabel setBackgroundColor:[UIColor whiteColor]];
    [opinionlabel setText:@"意见反馈"];
    [opinionlabel setFont:[UIFont systemFontOfSize:15.0]];
    [opinionbtn addSubview:opinionlabel];
    
    UILabel *aboutlabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 60, 15)];
    [aboutlabel setText:@"关于我们"];
    [aboutlabel setFont:[UIFont systemFontOfSize:15.0]];
    [aboutlabel setBackgroundColor:[UIColor whiteColor]];
    [aboutbtn addSubview:aboutlabel];
    
    UIImageView *cacheimageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20, 14,10,18)];
//    [cacheimageView setBackgroundColor:[UIColor blueColor]];
    [cacheimageView setImage:[UIImage imageNamed:@"ArrowRigt"]];
    [cachebtn addSubview:cacheimageView];
    
    UIImageView *opinionimageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20, 14,10,18)];
//    [opinionimageView setBackgroundColor:[UIColor blueColor]];
    [opinionimageView setImage:[UIImage imageNamed:@"ArrowRigt"]];
    [opinionbtn addSubview:opinionimageView];
    
    UIImageView *aboutimageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 20, 14,10,18)];
//    [aboutimageView setBackgroundColor:[UIColor blueColor]];
    [aboutimageView setImage:[UIImage imageNamed:@"ArrowRigt"]];
    [aboutbtn addSubview:aboutimageView];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.tabBarController setHidesBottomBarWhenPushed:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)cacheEvent:(UIButton *)sender
{
//    NSLog(@"11111");
//    NSLog(@"%lu", (unsigned long)[[SDImageCache sharedImageCache] getSize]/1024);
    [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
    
        //清除完成操作
        NSLog(@"wancheng");
    }];
}



- (void)opinionEvent:(UIButton *)sender
{
}



- (void)aboutEvent:(UIButton *)sender
{
    AboutUSViewController *aboutUsVC = [[AboutUSViewController alloc] init];
    aboutUsVC.titleString = @"关于我们";
    aboutUsVC.urlString = @"";
    [self.navigationController pushViewController:aboutUsVC animated:YES];
}


//退出登录
- (void)exitEvent:(UIButton *)sender
{
    [self.navigationController popToRootViewControllerAnimated:YES];
    [[NSUserDefaults standardUserDefaults] setValue:@"no" forKey:userLogin];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"fanhuishouye" object:nil];
}

//  back
- (void)leftEvent:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
